package com.mryang.hds.utils;


import lombok.Getter;

/**
 * @author Genius
 * @version 1.0.0
 * @ClassName ResultJson.java
 * @Description TODO 统一返回值信息
 * @createTime 2022年12月25日 19:28:00
 */


@Getter
public class ResultJson<T> {
    private Integer code;
    private T obj;
    private String message;

    private ResultJson(int code,String msg,T data){
        this.code = code;
        this.message = msg;
        this.obj = data;
    }

    private ResultJson(ResultCode resultCode, T obj) {
        this.code = resultCode.getCode();
        this.obj = obj;
        this.message = resultCode.getMessage();
    }
    private ResultJson(ResultCode resultCode, T obj,String message) {
        this.code = resultCode.getCode();
        this.obj = obj;
        this.message = message;
    }
    /*成功信息*/
    public static <T> ResultJson<T> success(T obj) {
        return new ResultJson<T>(ResultCode.SUCCESS,obj);
    }
    /*成功信息,自定义消息*/
    public static <T> ResultJson<T> success(T obj,String message) {
        return new ResultJson<T>(ResultCode.SUCCESS,obj, message);
    }
    public static <T> ResultJson<T> success(String message) {
        return new ResultJson<T>(ResultCode.SUCCESS,null, message);
    }

    /*自定义错误信息*/
    public static <T> ResultJson<T> error(ResultCode resultCode){
        return new ResultJson(resultCode, null);
    }

    public static <T> ResultJson<T> error(int code,String msg){
        return new ResultJson(code,msg, null);
    }

    /*错误信息*/
    public static <T> ResultJson<T> error() {
        return new ResultJson<T>(ResultCode.ERROR,null);
    }
    /*错误信息,自定义消息*/
    public static <T> ResultJson<T> error(String message) {
        return new ResultJson<T>(ResultCode.ERROR,null, message);
    }
    /*没有登录*/
    public static <T> ResultJson<T> noauth() {
        return new ResultJson<T>(ResultCode.NOAUTH,null);
    }
    /*没有权限*/
    public static <T> ResultJson<T> nopermission() {

        return new ResultJson<T>(ResultCode.NOPERMISSION,null);
    }

}
